﻿<!DOCTYPE html>

<html lang="zh-cn">
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit" />
    <title>操作你的PPT</title>
    <link rel="icon" href="/logo.ico">
    <style>
        div {
            font-size: 25px
        }
    </style>
</head>
<body>
    <div id="main" style="width:100vw;height:100vh;">
        <p id="note"></p>
    </div>
    <script src="hammer.min.js"></script>
    <script>
        function httpGet(url, cb) {
            fetch(url, {
                headers: {
                    'Content-Type': 'application/json; charset=UTF-8'
                },
                method: 'GET'
            }).then(response => response.text())
                .then(text => {
                    cb(text)
                })
                .catch(e => {
                    return null
                })
        }

        const note = document.querySelector("#note");

        let hasRun = true
        let getNotes = setInterval(() => {
            httpGet('/getNote', (text) => {
                
                note.innerText = text
            })
        }, 500)

        function nextPage() {
            httpGet('/next', (text) => {
                if (text == 'NO') {
                    clearInterval(getNotes)
                    note.innerText = "幻灯片播放完毕！"
                    hasRun = false
                } else {
                    if (!hasRun) {
                        getNotes = setInterval(() => {
                            httpGet('/getNote', (text) => {
                                note.innerText = text
                            })
                        }, 500)
                        hasRun = true
                    }
                }
            })
        }

        function previousPage() {
            httpGet('/previous', (text) => {
                if (text == 'NO') {
                    clearInterval(getNotes)
                    note.innerText = "幻灯片播放完毕！"
                    hasRun = false
                } else {
                    if (!hasRun) {
                        getNotes = setInterval(() => {
                            httpGet('/getNote', (text) => {
                                note.innerText = text
                            })
                        }, 500)
                        hasRun = true
                    }
                }
            })
        }

        var hammer = new Hammer(document.querySelector("#main"));
        hammer.on("swipeleft", function () {
            nextPage();
        });
        hammer.on("swiperight", function () {
            previousPage();
        });

        
    </script>
</body>
</html>